<template>
	<view class="content">
		<mescroll-uni ref="mescrollRef"  @init="mescrollInit"  @up="upCallback" :up="upOption"  :down="{use: false}">
			<view class="section-0">
				<view class="section-body">
					<view class="tab">
						<view  @click="setCurIdx(idx, item.id)" :class="`item ${curIdx === idx ? 'item__active' : ''} ${curIdx + 1 === idx ? 'item__active_next' : ''}`" v-for="(item, idx) in tabList" :key="item.id">
							<view class="label">{{item.name}}</view>
							<view class="shape">
								<view class="shape-body"></view>
							</view>
							<view class="shape shape-mirrow">
								<view class="shape-body"></view>
							</view>
						</view>
					</view>
					<view class="list" v-if="list.length">
						<view class="item" v-for="item in list" :key="item.id">
							<view class="left">
								<view class="name">{{item.project_name}}</view>
								<view class="time">
									履职人：<text style="margin-right: 20rpx;">{{item.user_name}}</text>
									<text style="float: right;">{{item.dk_time_in}}</text>
								</view>
								<view class="time">地点：<text>{{item.dk_address}}</text></view>
							</view>
						</view>
					</view>
					<!-- <view v-else>
						<view class="custom-empty">
							<text class="iconfont icon-zanwushuju"></text>
							<view class="empty-title">暂无数据</view>
						</view>
					</view> -->
				</view>
			</view>
		</mescroll-uni>
	</view>
</template>

<script>
	import { mapGetters, mapActions} from 'vuex';
	import { projectSignInIndexApi } from '@/api/duty.js';
	export default {
		data() {
			return {
				mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
				upOption:{
					textNoMore: '-- 没有更多了 --'
				},
				pageSize: 20,
				tabList: [
					{ id: 1, name: '现场考勤记录'},
					// { id: 2, name: '非现场履职'},
				],
				curIdx: 0,
				curId: 1,
				list: []
			}
		},
		computed: {
			...mapGetters({
				userInfo: 'system/getUserInfo', 
			}),
		},
		methods: {
			setCurIdx(idx, id) {
				this.curIdx = idx;
				this.curId = id;
				uni.showLoading({title: '加载中...'});
				setTimeout(() => {
					uni.hideLoading();
				}, 200)
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0,0);
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*上拉加载的回调*/
			async upCallback(page) {
				const {data} =  await projectSignInIndexApi({
					user_name: this.userInfo.nick_name,
					mark: this.curId === 1 ? '现场履职': '非现场履职',
					page: page.num,
					pageSize: this.pageSize
				});
				
				if (data.code === 1 || data.code === 200) {
					// 接口返回的当前页数据列表 (数组)
					let curPageData = data.data.data;
					// 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
					let curPageLen = curPageData.length; 
					// 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
					let totalPage = data.data.last_page; 
					//设置列表数据
					if(page.num == 1) this.list = []; //如果是第一页需手动置空列表
					this.list = this.list.concat(curPageData); //追加新数据
					// 请求成功,隐藏加载状态
					this.mescroll.endByPage(curPageLen, totalPage); 
					setTimeout(()=>{
						this.mescroll.endSuccess(curPageLen);
					},20);
				} else{
					//  请求失败,隐藏加载状态
					this.mescroll.endErr()
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #fff;
	}
	.section-0{
		width: 100%;
		background-color: #3759f2;
		.section-body{
			width: 100%;
			border-top-left-radius: 40rpx;
			border-top-right-radius: 40rpx;
			background-color: #1534ce;
			overflow: hidden;
			.tab{
				width: 100%;
				height: 80rpx;
				@include clear();
				background-color: #1534ce;
				.item{
					width: 100%;
					float: left;
					height: 80rpx;
					background-color: #1534ce;
					position: relative;
					.label{
						height: 80rpx;
						line-height: 80rpx;
						position: relative;
						z-index: 10;
						box-sizing: border-box;
						text-align: center;
						width: 100%;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: #ffffff;
					}
					.shape{
						z-index: 1;
						width: 50rpx;
						height: 50rpx;
						position: absolute;
						bottom: 0;
						left: -50rpx;
						background: #000;
						display: none;
						background-color: #fff;
						overflow: hidden;
						.shape-body{
							width: 50rpx;
							height: 50rpx;
							background-color: #1534ce;
							border-bottom-right-radius: 40rpx;
						}
					}
					.shape-mirrow{
						z-index: 1;
						left: 0;
						display: none;
						.shape-body{
							border-bottom-right-radius: 0rpx;
							border-bottom-left-radius: 40rpx;
						}
					}
				}
				.item__active{
					border-top-left-radius: 40rpx;
					border-top-right-radius: 40rpx;
					background-color: #fff;
					.label{
						color: #46464a;
					}
					.shape{
						display: block;
					}
					.shape-mirrow{
						display: none;
					}
				}
				.item__active_next{
					border-bottom-right-radius: 50rpx;
					.shape{
						display: none;
					}
					.shape-mirrow{
						display: block;
					}
				}
			}
			.list{
				padding-top: 30rpx;
				padding-left: 27rpx;
				padding-right: 27rpx;
				padding-bottom: 30rpx;
				box-sizing: border-box;
				background-color: #fff;
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;
				.item{
					width: 100%;
					background-color: #ffffff;
					border-radius: 35rpx;
					box-shadow: 0 0 20rpx 10rpx rgba(#bcbcb5, 0.17);
					box-sizing: border-box;
					padding: 30rpx;
					@include clear();
					margin-bottom: 23rpx;
					.left{
						float: left;
						width: 100%;
						.name{
							height: 30rpx;
							width: 100%;
							font-size: 26rpx;
							font-weight: bold;
							font-stretch: normal;
							line-height: 34rpx;
							letter-spacing: 0rpx;
							color: #46464a;
							padding-top: 5rpx;
						}
						.time{
							width: 100%;
							padding-top: 17rpx;
							font-size: 16rpx;
							font-weight: normal;
							font-stretch: normal;
							letter-spacing: 0rpx;
							color: #7f98ae;
						}
					}
					
				}
				
			}
		}
	}
</style>
